let manager = null;

Page({
  data: {
    src: "cloud://gpt-0grastut6153c6bb.6770-gpt-0grastut6153c6bb-1316585463/sounds/qsc.mp3",
    resps: [],
    collected: true
  },
  onLoad: function () {
    wx.cloud.init({
      env: 'gpt-0grastut6153c6bb' // 替换为您自己的云环境 ID
    });
  
    wx.cloud.callFunction({
      name: 'first', // 云函数的名称
      data: {
        name:"first"
        },
      success: res => {
        const result = res.result.result1;
        this.setData({
          show : result
        })
        // 处理云函数调用成功的结果
        console.log(result);
      },
      fail: err => {
        const result = res.result.result1;
        this.setData({
          show : result
        })
        // 处理云函数调用失败的错误
        console.error(err);
      }
    });
    this.yuyinPlay();
    this.setData({
      collected: true
    })
    this.innerAudioContext.pause();
  },
  audioPlay() {
    this.yuyinPlay();
    this.setData({
      isPlay: true
    })
  },
  yuyinPlay: function (e) {
    this.setData({
      collected: false
    })
    let that = this
    //创建内部 audio 上下文 InnerAudioContext 对象。
    that.innerAudioContext = wx.createInnerAudioContext();

    that.innerAudioContext.src = this.data.src //设置音频地址
    this.innerAudioContext.play(); //播放音频
  },
  end: function (e) {
    let that = this
    if ((that.data.src) || (that.data.src != undefined)) return
    that.innerAudioContext.pause();//暂停音频 
  },
  pause: function () {
    isPlay:false,
    this.setData({
      collected: true
    })
    this.innerAudioContext.pause();
  },
  onHide: function () {
    this.pause()
    this.innerAudioContext.pause();
  },
  onUnload: function () {
    this.pause()
    this.innerAudioContext.pause();
  },
})
